package com.shz.pojo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * <p>
 * 
 * </p>
 *
 * @author yixin
 * @since 2024-06-04
 */
@Data
public class User implements UserDetails,Serializable  {

    private static final long serialVersionUID = 1L;
    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "用户id")
    private Integer id;

    @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    @ApiModelProperty(value = "用户名实际上是电话")
    private String username;
    @ApiModelProperty(value = "姓名")
    private String name;
    @ApiModelProperty(value = "密码")
    private String password;
    @TableField("study_course")
    private Integer studyCourse;
    @TableField("year_course")
    private Integer yearCourse;
    @ApiModelProperty(value = "普通用户权限一律是0")
    private Integer roleName=0;
    @ApiModelProperty(value = "身份证")
    private String idcard;
    @ApiModelProperty(value = "职位")
    private String position;
    @ApiModelProperty(value = "部门")
    private String department;
    @ApiModelProperty(value = "邮箱")
    private String email;
    private Boolean status;
    private String avatar;


    @Override
    @JsonIgnore
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }


    @Override
    @JsonIgnore
    public List<GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> authorities = new ArrayList<>();
        authorities.add(new SimpleGrantedAuthority("ROLE_" + roleName ));
        return authorities;
    }
}
